package com.simba.server.jsonservice.serivces;

import java.sql.Timestamp;
import org.apache.log4j.Logger;
import org.jboss.netty.channel.Channel;
import org.json.JSONException;
import org.json.JSONObject;
import com.simba.common.jsonservice.JsonService;
import com.simba.common.log.LogUtil;
import com.simba.server.components.SlotManager;
import com.simba.server.components.SortControllerManager;
import com.simba.server.components.SortProtocolCreator;
import com.simba.server.components.data.SlotInfo;

public class SlotsPackJsonService implements JsonService
{
	public static final String NAME = "SlotsPack";
	private final static Logger logger = Logger.getLogger(SlotsPackJsonService.class);

	@Override
	public void handleRequest(Channel channel, Object content)
	{
		try
		{
			SlotInfo[] slotInfoList = SlotManager.getInstance().getSlotInfoList();
			for (SlotInfo slotInfo : slotInfoList)
			{
				slotInfo.setSlotType("1");
				SortControllerManager.getInstance().onSlotPackMessage(slotInfo);
			}

			Timestamp clearTime = SortProtocolCreator.getInstance().createCurrentTimeStamp();
			LogUtil.LogDebug(SlotsPackJsonService.logger,
					"Slots Pack Json Service request name : " + clearTime.toString());
		}
		catch (JSONException ex)
		{
			LogUtil.LogError(SlotsPackJsonService.logger,
					"SlotsPack Json Service Error : " + ex.getMessage());
		}
	}
}
